from typing import *
from bisect import bisect_left


class Solution:
    def minimizeMax(self, nums: List[int], p: int) -> int:
        nums = sorted(nums)

        def f(m):
            last, cnt = -1, 0
            for i, v in enumerate(nums):
                if i - 1 != last and v - nums[i - 1] <= m:
                    cnt += 1
                    last = i
            return cnt >= p

        return bisect_left(range(10**9), True, key=lambda a: f(a))


s = Solution()
print(s.minimizeMax(nums=[10, 1, 2, 7, 1, 3], p=2))
